<?php

use think\facade\Route;

Route::pattern([
    'catdir'  => '[A-Za-z0-9_\-]+', // 栏目的父级英文目录
    'catname' => '[A-Za-z0-9_\-]+', // 栏目英文目录名称
    'catid'   => '\d+',  // 栏目ID
    'id'      => '[A-Za-z0-9_\-]+',    // 文章ID或文章别名
    'model'   => '[A-Za-z0-9_\-]+',  // 模型标识
    'year'    => '\d+',  // 年、月、日
    'month'   => '\d+',
    'day'     => '\d+',
    'page'    => '\d+',
    'lang'    => '[A-Za-z_\-]+'
]);

$site                = get_config();
$site['url_rewrite'] = config('url_rewrite');
if (isset($site['url_mode']) && $site['url_mode'] == 1 && ! empty($site['url_rewrite'])) {
    // 伪静态
    foreach ($site['url_rewrite'] as $key => $value) {
        foreach ($value as $k => $v) {
            $v   = explode('.', $v);
            $ext = ! empty($v[1]) ? $v[1] : '';
            if (stripos($key, '/') !== 0) {
                $key = '/'.$key;
            }
            Route::rule($v[0], $key);
        }
    }
}
